package org.example.rabbitmq.product.config.listener;

import lombok.AllArgsConstructor;
import org.example.rabbitmq.common.event.MessageFailEvent;
import org.example.rabbitmq.common.message.MessageFail;
import org.example.rabbitmq.product.config.rabbitmq.RabbitSendFailSaveToDb;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * @author hzq
 * @date 2021/11/25 11:15
 */
@Component
@AllArgsConstructor
public class MessageFailListener implements ApplicationListener<MessageFailEvent> {

    private final RabbitSendFailSaveToDb rabbitSendFailSaveToDb;

    @Override
    public void onApplicationEvent(MessageFailEvent event) {
        MessageFail messageFail = (MessageFail) event.getSource();
        rabbitSendFailSaveToDb.saveToMysql(messageFail);
    }
}
